package com.drug.controller;

import com.drug.domain.Country;
import com.drug.domain.Hospital;
import com.drug.domain.Result;
import com.drug.mapper.CountryMapper;
import com.drug.mapper.HospitalMapper;
import com.drug.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private HospitalMapper hospitalMapper;
    @Autowired
    private CountryMapper countryMapper;

    //多条件查询医院
    @ResponseBody
    @RequestMapping("/selectHospital")
    public List<Hospital> selectHospital(Hospital hospital){
        System.err.println(hospital);
        return hospitalService.selectHospital(hospital);

    }

    //分页查询
    @RequestMapping("/selectHospitalAll")
    @ResponseBody
    public Result pageFindAll(@RequestParam(required=true,defaultValue="1")Integer pageNum){
        return hospitalService.pageFindAll(pageNum);
    }

    //逻辑删除
    @ResponseBody
    @RequestMapping("/deleteHospital")
    public String deleteHospital(Integer hId){
        hospitalService.deleteHospital(hId);
        return "drug hospital";
    }


    //添加医院
    @ResponseBody
    @RequestMapping("/insertHospital")
    public void insertHospital(Hospital hospital){
        hospitalService.insertHospital(hospital);
    }

    //修改医院
    @ResponseBody
    @RequestMapping("/updateHospital")
    public List<Hospital> updateHospital(Hospital hospital){
        System.err.println(hospital);
        return hospitalService.updateHospital(hospital);
    }

    //查询地区
    @ResponseBody
    @RequestMapping("/selectCountry")
    public List<Country> selectCountry() {
        List<Country> countries = countryMapper.selectCountry();
        return countries;
    }

     //回显搜索
    @ResponseBody
    @RequestMapping("/selectById")
    public Hospital selectById(String hid){
        Hospital hospital = hospitalMapper.selectById(Integer.valueOf(hid));
        System.err.println(hospital);
        return hospital;
    }
    //查询医院名
    @ResponseBody
    @RequestMapping("/findhospitalname")
    public Result findUsername(String hname){
        return hospitalService.selectHname(hname);
    }
}
